package com.example.system.controller.exam;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.Result;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.exam.dto.ExamAddDTO;
import com.example.system.domain.exam.dto.ExamEditDTO;
import com.example.system.domain.exam.dto.ExamQueryDTO;
import com.example.system.domain.exam.dto.ExamQuestionAddDTO;
import com.example.system.domain.exam.vo.ExamDetailVO;
import com.example.system.service.exam.IExamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    //获取竞赛列表
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        log.error(examQueryDTO.toString());
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    //新增竞赛,不包含题目
    @PostMapping("/add")
    public Result<String> add(@Validated @RequestBody ExamAddDTO examAddDTO) {
        return Result.ok(examService.add(examAddDTO));
    }

    //新增竞赛中的题目
    @PostMapping("/question/add")
    public Result<Void> questionAdd(@Validated @RequestBody ExamQuestionAddDTO examQuestionAddDTO) {
        return toResult(examService.questionAdd(examQuestionAddDTO));
    }

    //删除竞赛中的题目
    @DeleteMapping("/question/delete")
    public Result<Void> questionDelete(Long examId,Long questionId) {
        return toResult(examService.questionDelete(examId,questionId));
    }

    //用户详情页
    @GetMapping("/detail")
    public Result<ExamDetailVO> detail(Long examId) {
        return Result.ok(examService.detail(examId));
    }

    //修改竞赛信息
    @PutMapping("edit")
    public Result<Void> edit(@RequestBody ExamEditDTO examEditDTO){
        return toResult(examService.edit(examEditDTO));
    }

    //删除竞赛
    @DeleteMapping("/delete")
    public Result<Void> delete(Long examId){
        return toResult(examService.delete(examId));
    }

    //竞赛发布
    @PutMapping("/publish")
    public Result<Void> publish(Long examId){
        return toResult(examService.publish(examId));
    }

    //竞赛撤销发布
    @PutMapping("/cancelPublish")
    public Result<Void> cancelPublish(Long examId){
        return toResult(examService.cancelPublish(examId));
    }
}
